



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class FoldersDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public FoldersDB()
        {
        }

        public FoldersDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Folders> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Folders> lstRet = new List<Folders>();

            string strQuery = " select " + strTop  + " * from dbo.[Folders]  " ;

            strWhere = GlobalThings.getWhereWithoutDeleted(strWhere);


            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Folders obj = new Folders();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["FolderNameAR"] != DBNull.Value)
                    {
                        obj.FolderNameAR = (System.String)dr["FolderNameAR"];
                    }
                    else
                    {
                        obj.FolderNameAR = "";
                    } 
 if (dr["FolderNameEN"] != DBNull.Value)
                    {
                        obj.FolderNameEN = (System.String)dr["FolderNameEN"];
                    }
                    else
                    {
                        obj.FolderNameEN = "";
                    } 
 if (dr["ParentID"] != DBNull.Value)
                    {
                        obj.ParentID = (System.Int64?)dr["ParentID"];
                    }
                    else
                    {
                        obj.ParentID = null;
                    } 
 if (dr["StatusID"] != DBNull.Value)
                    {
                        obj.StatusID = (System.Int64)dr["StatusID"];
                    }
                    else
                    {
                        obj.StatusID = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Folders> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Folders> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Folders obj)
        {
            
            

                    DbParameter prmFolderNameAR = con.createParameter();
                    prmFolderNameAR.ParameterName = "@FolderNameAR";
                    prmFolderNameAR.DbType =DbType.String;
                    if (obj.FolderNameAR == null)
                    {
                        prmFolderNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmFolderNameAR.Value = obj.FolderNameAR;
                    }
                

                    


                    DbParameter prmFolderNameEN = con.createParameter();
                    prmFolderNameEN.ParameterName = "@FolderNameEN";
                    prmFolderNameEN.DbType =DbType.String;
                    if (obj.FolderNameEN == null)
                    {
                        prmFolderNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmFolderNameEN.Value = obj.FolderNameEN;
                    }
                

                    


                    DbParameter prmParentID = con.createParameter();
                    prmParentID.ParameterName = "@ParentID";
                    prmParentID.DbType =DbType.Int64;
                    if (obj.ParentID == null)
                    {
                        prmParentID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmParentID.Value = obj.ParentID;
                    }
                

                    


                    DbParameter prmStatusID = con.createParameter();
                    prmStatusID.ParameterName = "@StatusID";
                    prmStatusID.DbType =DbType.Int64;
                    if (obj.StatusID == null)
                    {
                        prmStatusID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusID.Value = obj.StatusID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Folders] ([FolderNameAR],[FolderNameEN],[ParentID],[StatusID]) VALUES (@FolderNameAR,@FolderNameEN,@ParentID,@StatusID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmFolderNameAR,prmFolderNameEN,prmParentID,prmStatusID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Folders obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Folders obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmFolderNameAR = con.createParameter();
                    prmFolderNameAR.ParameterName = "@FolderNameAR";
                    prmFolderNameAR.DbType =DbType.String;
                    if (obj.FolderNameAR == null)
                    {
                        prmFolderNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmFolderNameAR.Value = obj.FolderNameAR;
                    }
                

                    


                    DbParameter prmFolderNameEN = con.createParameter();
                    prmFolderNameEN.ParameterName = "@FolderNameEN";
                    prmFolderNameEN.DbType =DbType.String;
                    if (obj.FolderNameEN == null)
                    {
                        prmFolderNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmFolderNameEN.Value = obj.FolderNameEN;
                    }
                

                    


                    DbParameter prmParentID = con.createParameter();
                    prmParentID.ParameterName = "@ParentID";
                    prmParentID.DbType =DbType.Int64;
                    if (obj.ParentID == null)
                    {
                        prmParentID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmParentID.Value = obj.ParentID;
                    }
                

                    


                    DbParameter prmStatusID = con.createParameter();
                    prmStatusID.ParameterName = "@StatusID";
                    prmStatusID.DbType =DbType.Int64;
                    if (obj.StatusID == null)
                    {
                        prmStatusID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusID.Value = obj.StatusID;
                    }
                

                    


           



            string strQuery = " update dbo.[Folders] set [FolderNameAR]=@FolderNameAR,[FolderNameEN]=@FolderNameEN,[ParentID]=@ParentID,[StatusID]=@StatusID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmFolderNameAR,prmFolderNameEN,prmParentID,prmStatusID);

            

        }


        public void Update(Folders obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Folders obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Folders]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Folders obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Folders> getFoldersByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Folders> lstRet = new List<Folders>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Folders> getFoldersByID(System.Int64 ID)
                    {
                        List<Folders> lstRet = new List<Folders>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getFoldersByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Folders> getFoldersByFolderNameAR(ClassDataHandler con,System.String FolderNameAR)
                    {
                        List<Folders> lstRet = new List<Folders>();


                        DbParameter prmFolderNameAR = con.createParameter();
                        prmFolderNameAR.ParameterName = "@FolderNameAR";
                        prmFolderNameAR.DbType = DbType.String;
                        if (FolderNameAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmFolderNameAR.Value = FolderNameAR;
                        }


                        lstRet = Select(con, "" , " where [FolderNameAR]=@FolderNameAR ", prmFolderNameAR);



                        return lstRet;

                    }


                    public List<Folders> getFoldersByFolderNameAR(System.String FolderNameAR)
                    {
                        List<Folders> lstRet = new List<Folders>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getFoldersByFolderNameAR(con, FolderNameAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Folders> getFoldersByFolderNameEN(ClassDataHandler con,System.String FolderNameEN)
                    {
                        List<Folders> lstRet = new List<Folders>();


                        DbParameter prmFolderNameEN = con.createParameter();
                        prmFolderNameEN.ParameterName = "@FolderNameEN";
                        prmFolderNameEN.DbType = DbType.String;
                        if (FolderNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmFolderNameEN.Value = FolderNameEN;
                        }


                        lstRet = Select(con, "" , " where [FolderNameEN]=@FolderNameEN ", prmFolderNameEN);



                        return lstRet;

                    }


                    public List<Folders> getFoldersByFolderNameEN(System.String FolderNameEN)
                    {
                        List<Folders> lstRet = new List<Folders>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getFoldersByFolderNameEN(con, FolderNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Folders> getFoldersByParentID(ClassDataHandler con,System.Int64? ParentID)
                    {
                        List<Folders> lstRet = new List<Folders>();


                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType = DbType.Int64;
                        if (ParentID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmParentID.Value = ParentID;
                        }


                        lstRet = Select(con, "" , " where [ParentID]=@ParentID ", prmParentID);



                        return lstRet;

                    }


                    public List<Folders> getFoldersByParentID(System.Int64? ParentID)
                    {
                        List<Folders> lstRet = new List<Folders>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getFoldersByParentID(con, ParentID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Folders> getFoldersByStatusID(ClassDataHandler con,System.Int64 StatusID)
                    {
                        List<Folders> lstRet = new List<Folders>();


                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType = DbType.Int64;
                        if (StatusID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmStatusID.Value = StatusID;
                        }


                        lstRet = Select(con, "" , " where [StatusID]=@StatusID ", prmStatusID);



                        return lstRet;

                    }


                    public List<Folders> getFoldersByStatusID(System.Int64 StatusID)
                    {
                        List<Folders> lstRet = new List<Folders>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getFoldersByStatusID(con, StatusID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Folders> Search(ClassDataHandler con, Folders obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.FolderNameAR != "")
                    {
                        DbParameter prmFolderNameAR = con.createParameter();
                        prmFolderNameAR.ParameterName = "@FolderNameAR";
                        prmFolderNameAR.DbType =DbType.String;
                        if (obj.FolderNameAR == null)
                        {
                            prmFolderNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmFolderNameAR.Value = obj.FolderNameAR;
                        }
                        strWhere += " [FolderNameAR]=@FolderNameAR AND ";
                        lstParameters.Add(prmFolderNameAR);
                     }



                    

                    if (obj.FolderNameEN != "")
                    {
                        DbParameter prmFolderNameEN = con.createParameter();
                        prmFolderNameEN.ParameterName = "@FolderNameEN";
                        prmFolderNameEN.DbType =DbType.String;
                        if (obj.FolderNameEN == null)
                        {
                            prmFolderNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmFolderNameEN.Value = obj.FolderNameEN;
                        }
                        strWhere += " [FolderNameEN]=@FolderNameEN AND ";
                        lstParameters.Add(prmFolderNameEN);
                     }



                    

                    if (obj.ParentID != null)
                    {
                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType =DbType.Int64;
                        if (obj.ParentID == null)
                        {
                            prmParentID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmParentID.Value = obj.ParentID;
                        }
                        strWhere += " [ParentID]=@ParentID AND ";
                        lstParameters.Add(prmParentID);
                     }



                    

                    if (obj.StatusID != -1)
                    {
                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType =DbType.Int64;
                        if (obj.StatusID == null)
                        {
                            prmStatusID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusID.Value = obj.StatusID;
                        }
                        strWhere += " [StatusID]=@StatusID AND ";
                        lstParameters.Add(prmStatusID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Folders> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Folders> Search(Folders obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Folders> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Folders> SearchOrLike(ClassDataHandler con, Folders obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.FolderNameAR != "")
                    {
                        DbParameter prmFolderNameAR = con.createParameter();
                        prmFolderNameAR.ParameterName = "@FolderNameAR";
                        prmFolderNameAR.DbType =DbType.String;
                        if (obj.FolderNameAR == null)
                        {
                            prmFolderNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmFolderNameAR.Value = obj.FolderNameAR;
                        }
                        strWhere += " [FolderNameAR] LIKE @FolderNameAR OR ";
                        lstParameters.Add(prmFolderNameAR);
                     }



                    

                    if (obj.FolderNameEN != "")
                    {
                        DbParameter prmFolderNameEN = con.createParameter();
                        prmFolderNameEN.ParameterName = "@FolderNameEN";
                        prmFolderNameEN.DbType =DbType.String;
                        if (obj.FolderNameEN == null)
                        {
                            prmFolderNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmFolderNameEN.Value = obj.FolderNameEN;
                        }
                        strWhere += " [FolderNameEN] LIKE @FolderNameEN OR ";
                        lstParameters.Add(prmFolderNameEN);
                     }



                    

                    if (obj.ParentID != null)
                    {
                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType =DbType.Int64;
                        if (obj.ParentID == null)
                        {
                            prmParentID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmParentID.Value = obj.ParentID;
                        }
                        strWhere += " [ParentID]=@ParentID OR ";
                        lstParameters.Add(prmParentID);
                     }



                    

                    if (obj.StatusID != -1)
                    {
                        DbParameter prmStatusID = con.createParameter();
                        prmStatusID.ParameterName = "@StatusID";
                        prmStatusID.DbType =DbType.Int64;
                        if (obj.StatusID == null)
                        {
                            prmStatusID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusID.Value = obj.StatusID;
                        }
                        strWhere += " [StatusID]=@StatusID OR ";
                        lstParameters.Add(prmStatusID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Folders> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Folders> SearchOrLike(Folders obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Folders> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            